﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using dotNails.CodeGen.T4;

namespace dotNails.CodeGen.Models.dotNails {
	/// <summary>
	/// Summary description for ControllerTemplate.
	/// </summary>
	public class View : T4Template {
		private string _dataContextClass { get; set; }
		private string _viewNamespace = string.Empty;
		private string _modelNamespace = string.Empty;
		private string _commonNamespace = string.Empty;
		private string _pageTitle = string.Empty;
		private StringBuilder _entityBaseClass = new StringBuilder();

		public View(string viewName, string templateName, string pageTitle, Table table, string dataContextClass, string viewNamespace, string modelNamespace, string commonNamespace)
			: base(table) {
			TemplateFileName = Path.Combine(TemplatePath, templateName + ".tt");
			_dataContextClass = dataContextClass;
			_viewNamespace = viewNamespace;
			_modelNamespace = modelNamespace;
			_commonNamespace = commonNamespace;
			_pageTitle = pageTitle;
			_entityBaseClass.Append("System.Web.Mvc.ViewPage<");
			if (viewName == "Index") {
				_entityBaseClass.Append("IPagedList<");
			}
			_entityBaseClass.Append(_modelNamespace).Append(".").Append(Table.Type.Name);
			if (viewName == "Index") {
				_entityBaseClass.Append(">");
			}
			_entityBaseClass.Append(">");
		}
		
		protected override string AddTemplateProperties() {
			return
				@"
	public string EntityBaseClass = """ + _entityBaseClass + @""";
	public string Namespace = """ + _viewNamespace + @""";
	public string EntityClass = """ + Table.Type.Name + @""";
	public string DataContextClass = """ + _dataContextClass + @""";
	public string ModelNamespace = """ + _modelNamespace + @""";
	public string CommonNamespace = """ + _commonNamespace + @""";
	public string PageTitle = """ + _pageTitle + @""";";
		}

	}
}